<!DOCTYPE HTML>
<html>
<head>
<#include "/adminPage/common.html"/>
<style type="text/css">
</style>
</head>
<body class="layui-layout-body">
	<div class="layui-layout layui-layout-admin">

		<#include "/adminPage/header.html"/>
		<#include "/adminPage/menu.html"/>

		<div class="layui-body">
			<!-- 内容主体区域 -->
			<div style="padding: 15px">
				<fieldset class="layui-elem-field layui-field-title">
					<legend>容器管理</legend>
				</fieldset>


				<form action="${ctx}/adminPage/docker" id="searchForm" method="post">

					<div class="layui-form">

						<div class="layui-inline">
							<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="add()">创建容器</button>
						</div>

						<div class="layui-inline">
							<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" onclick="run()">直接执行命令</button>
						</div>

						<div class="layui-inline">
							<label class="layui-form-label">关键字</label>
						</div>
						<div class="layui-inline">
							<input type="text" name="keywords" class="layui-input" style="height: 30px;" value="${keywords}">
						</div>

						<div class="layui-inline">
							<button type="button" class="layui-btn layui-btn-sm" onclick="search()">搜索</button>
						</div>
					</div>


				</form>

				<table class="layui-table" lay-size="sm">
					<thead>
						<tr>
							<th>容器名 / ID</th>
							<th>镜像</th>
							<th>命令</th>
							<th>创建时间</th>
							<th>状态</th>
							<th>端口映射</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<#list list as containerExt>
						<tr>
							<td>
								${containerExt.nameStr}
								<br>
								${containerExt.id}
							</td>
							<td>${containerExt.image}</td>
							<td>${containerExt.command}</td>
							<td>${(containerExt.created * 1000)?number_to_datetime?string('yyyy-MM-dd HH:mm:ss')}</td>
							<td>
								<#if containerExt.run==0> <span class="red">已停止 ${containerExt.status}</span> </#if>
								<#if containerExt.run==1> <span class="green">已启动 ${containerExt.status}</span> </#if>

							</td>
							<td>${containerExt.portStr}</td>
							<td>
								<#if containerExt.run==0>
								<div class="layui-inline">
									<button class="layui-btn layui-btn-normal layui-btn-sm" onclick="start('${containerExt.id}')">启动</button>
								</div>
								</#if>

								<#if containerExt.run==1>
								<div class="layui-inline">
									<button class="layui-btn layui-btn-danger layui-btn-sm" onclick="stop('${containerExt.id}')">停止</button>
								</div>
								</#if>
								<div class="layui-inline">
									<button class="layui-btn layui-btn-sm" onclick="ssh('${containerExt.id}')">终端</button>
								</div>
								<div class="layui-inline">
									<button class="layui-btn layui-btn-sm" onclick="logs('${containerExt.id}')">日志</button>
								</div>
								<div class="layui-inline">
									<button class="layui-btn layui-btn-danger layui-btn-sm" onclick="del('${containerExt.id}')">删除</button>
								</div>

							</td>
						</tr>
						</#list>
					</tbody>
				</table>

			</div>
		</div>
	</div>

	<div style="height: 0px; width: 0px; overflow: hidden;">
		<!-- 弹出框 -->
		<div class="layui-form" id="windowDiv" style="padding: 15px; display: none">
			<form id="addForm">

				<div class="layui-form-item">
					<label class="layui-form-label">
						名称
						<span class="red">*</span>
					</label>
					<div class="layui-input-inline" style="width: 400px;">
						<input type="text" name="name" id="name" class="layui-input">
					</div>
				</div>


				<div class="layui-form-item">
					<label class="layui-form-label">
						镜像
						<span class="red">*</span>
					</label>
					<div class="layui-input-inline" style="width: 400px;">
						<select name="image" id="image">

						</select>
					</div>
				</div>



				<div class="layui-form-item">
					<label class="layui-form-label"> 端口映射 </label>

					<div class="layui-input-inline">
						<input type="number" id="localPort" class="layui-input" placeholder="本机端口">
					</div>

					<div class="layui-input-inline">
						<input type="number" id="dockerPort" class="layui-input" placeholder="docker端口">
					</div>
					<button type="button" class="layui-btn" onclick="addPort()">添加</button>
				</div>


				<div class="layui-form-item">
					<label class="layui-form-label"> </label>

					<div class="layui-input-block">
						<table class="layui-table" lay-size="sm" style="width: 400px;">
							<thead>
								<tr>
									<th>本机端口</th>
									<th>容器端口</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody id="portTable">

							</tbody>
						</table>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label"> 目录映射 </label>
					<div class="layui-input-inline">
						<input type="text" id="localDir" class="layui-input" placeholder="本机目录">
					</div>

					<div class="layui-input-inline">
						<input type="text" id="dockerDir" class="layui-input" placeholder="docker目录">
					</div>
					<button type="button" class="layui-btn" onclick="addDir()">添加</button>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label"> </label>

					<div class="layui-input-block">
						<table class="layui-table" lay-size="sm" style="width: 400px;">
							<thead>
								<tr>
									<th>本机目录</th>
									<th>容器目录</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody id="dirTable">

							</tbody>
						</table>
					</div>
				</div>


				<div class="layui-form-item">
					<label class="layui-form-label"> 环境变量 </label>

					<div class="layui-input-inline">
						<input type="text" id="paramName" class="layui-input" placeholder="参数名">
					</div>

					<div class="layui-input-inline">
						<input type="text" id="paramValue" class="layui-input" placeholder="参数值">
					</div>
					<button type="button" class="layui-btn" onclick="addParam()">添加</button>
				</div>


				<div class="layui-form-item">
					<label class="layui-form-label"> </label>

					<div class="layui-input-block">
						<table class="layui-table" lay-size="sm" style="width: 400px;">
							<thead>
								<tr>
									<th>参数名</th>
									<th>参数值</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody id="paramTable">

							</tbody>
						</table>
					</div>
				</div>


				<div class="layui-form-item">
					<label class="layui-form-label"> 启动参数 </label>

					<div class="layui-input-inline">
						<input type="text" id="cmdName" class="layui-input" placeholder="参数名">
					</div>

					<div class="layui-input-inline">
						<input type="text" id="cmdValue" class="layui-input" placeholder="参数值">
					</div>
					<button type="button" class="layui-btn" onclick="addCmd()">添加</button>
				</div>


				<div class="layui-form-item">
					<label class="layui-form-label"> </label>

					<div class="layui-input-block">
						<table class="layui-table" lay-size="sm" style="width: 400px;">
							<thead>
								<tr>
									<th>参数名</th>
									<th>参数值</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody id="cmdTable">

							</tbody>
						</table>
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label"> 内存配额</label>
					<div class="layui-input-inline" style="width: 400px;">
						<input type="number" name="member" id="member" class="layui-input" placeholder="单位: MB">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label"> CPU权重 </label>
					<div class="layui-input-inline" style="width: 400px;">
						<input type="number" name="cpu" id="cpu" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label"> 执行命令 </label>
					<div class="layui-input-inline" style="width: 400px;">
						<input type="text" name="command" id="command" class="layui-input" placeholder="例: /bin/sh">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label"> 特权模式 </label>
					<div class="layui-input-inline">
						<input type="checkbox" id="root" name="root" title="" lay-skin="primary">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label"> 开机自启动 </label>
					<div class="layui-input-inline">
						<input type="checkbox" id="autoStart" name="autoStart" title="" lay-skin="primary">
					</div>
				</div>



				<div class="layui-form-item" style="text-align: center;">
					<button type="button" class="layui-btn layui-btn-normal" onclick="buildDockerCmd()">添加</button>
					<button type="button" class="layui-btn" onclick="layer.closeAll()">关闭</button>
				</div>
			</form>
		</div>


		<div class="layui-form" id="sshDiv" style="padding: 15px; display: none">
			<form id="sshForm">
				<div class="layui-form-item">
					<label class="layui-form-label">终端命令</label>
					<div class="layui-input-block">
						<select id="cmd" name="cmd">
							<option>/bin/sh</option>
							<option>/bin/bash</option>
							<option>/bin/ash</option>
						</select>
					</div>
				</div>

				<div class="layui-form-item center">
					<button type="button" class="layui-btn layui-btn-normal" onclick="sshOver()">提交</button>
					<button type="button" class="layui-btn" onclick="layer.closeAll()">关闭</button>
				</div>
			</form>
		</div>
	</div>

	<script src="${ctx}/js/adminPage/docker/index.js?v=${jsrandom}" type="text/javascript"></script>
</body>


</html>